// 全局混入的属性与方法
const globalConfig = require('@/config')
const moduleConfig = require('../config')
const modelUtil = require('@/utils/model')
const layerUtil = require('@/utils/layer')
const routerUtil = require('@/router/util')
const computedModule = require('../computed/index')
const watchModule = require('../watch/index')

// page component 公用混入配置
const getPublicMixin = () => {
  return {
    data: {
      $static: globalConfig.staticPath
    },
    ...routerUtil,
    ...layerUtil,
    ...modelUtil
  }
}
module.exports = {
  // 页面混入属性与方法
  globalMixins_page: {
    ...getPublicMixin(),
    onLoad() {
      if (moduleConfig.openGlobalComputed_page) {
        computedModule.call(this)
      }
      if (moduleConfig.openGlobalWatch_page) {
        watchModule.call(this)
      }
    }

  },
  // 组件混入属性与方法
  globalMixins_component: {
    ...getPublicMixin(),
    attached() {
      if (moduleConfig.openGlobalComputed_component) {
        computedModule.call(this, false)
      }
      if (moduleConfig.openGlobalWatch_component) {
        watchModule.call(this, false)
      }
    }
  }
}
